package app.r_teenus.frontend.controller;


import org.springframework.binding.message.MessageBuilder;
import org.springframework.binding.message.MessageContext;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import app.r_teenus.backend.model.Device;


@Component
public class DeviceValidator {

	/**
	 * Spring Web Flow activated validation (validate + ${state}). Validates 'deviceForm' view state after binding to person.
	 */
	public void validateDeviceForm(Device device, MessageContext context) {
		if (!StringUtils.hasText(device.getName())) {
			context.addMessage(new MessageBuilder().error().source("name").code("device.form.name.required").build());
		} 
	}
}
